package yxy.game.pm2.module.arena.toparena;

import com.alibaba.fastjson.JSON;
import org.joda.time.DateTime;
import yxy.apple.logger.Logger;
import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.arenarankreward;
import yxy.cherry.data.string.GameString;
import yxy.game.pm2.bean.Constant;
import yxy.game.pm2.bean.Currency;
import yxy.game.pm2.bean.area.AreaBean;
import yxy.game.pm2.bean.currency.Currencies;
import yxy.game.pm2.bean.module.RedisLock;
import yxy.game.pm2.bean.module.rank.RankEntry;
import yxy.game.pm2.bean.mq.CCReason;
import yxy.game.pm2.bean.timeline.JobHandle;
import yxy.game.pm2.module.arena.RankArena;
import yxy.game.pm2.module.mail.MailHandle;
import yxy.game.pm2.module.mail.MailTypeEnum;
import yxy.game.pm2.module.player.RankPlayerPower;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 巅峰赛定时器
 *
 * @ClassName TopAreanFuture
 * @Author jingtao-zheng
 * @Date 2022/9/11 17:18
 * @Version 1.0
 **/
public class TopAreanFuture  extends JobHandle {
    protected static Logger logger = Logger.create(TopAreanFuture.class);

    @Override
    public int jobType() {
        return JobHandle.JOB_TYPE_CROND;//定时
    }

    @Override
    public String crond() {
        /**
         * 每天这5个点执行一次
         * xxxx-xx-xx 05:00:01
         * xxxx-xx-xx 19:00:01
         * xxxx-xx-xx 20:00:01
         * xxxx-xx-xx 21:00:01
         * xxxx-xx-xx 22:00:01
         */
        return "1 0 0,5,19,20,21,22 * * ?";
    }

    @Override
    public long period() {
        return 0;
    }

    @Override
    public void init() {
        handle();
    }

    @Override
    public void tick() {
        logger.info("巅峰赛间隔执行,执行时间:%s",DateTime.now());
        handle();//后续间隔执行
    }

    private void handle() {
        //过滤没合并过的区
        Collection<AreaBean> areaBeans = AreaBean
                .all()
                .stream()
                .filter(_areaBean -> !_areaBean.isMeraged())
                .collect(Collectors.toList());
        for (AreaBean areaBean : areaBeans) {
            RedisLock lock = TopAreanModule.lock(areaBean.getGroupId());
            try {
                if (lock.tryLock()) {
                    TopAreanModule topAreanModule = TopAreanModule.get(areaBean.getAreaId());
                    update(topAreanModule);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }

    }

    private void update(TopAreanModule topAreanModule) {
        /**
         * 合服的处理
         * 区活动全部重置,并返还竞猜奖励
         *
         * 初始化新活动的条件
         * 1.isRunning为false  --- 保证了结算完成-邮件奖励都发完了
         * 2.当前时间大于开始时间3天 --- 保证流程走完
         */
        DateTime now = DateTime.now();
        if (checkCondition(topAreanModule, now)) {
            initTopArean(topAreanModule, now);
        }

        //当前时间大于当前状态的结束时间,进入下一个状态,直到
        if (now.isAfter(topAreanModule.getStateTimes().get(topAreanModule.getState()))) {
            if(topAreanModule.getState().equals(TopAreanHandle.TopAreanEnum.STEP_OFFSEASON)){
                return;
            }
            try {
                logger.info("巅峰赛if入口：%s区,当前%s状态,当前状态的结束时间%s,",
                        topAreanModule.getAreaId(),
                        topAreanModule.getState().name(),
                        topAreanModule.getStateTimes().get(topAreanModule.getState()));
            } catch (Exception e) {
                e.printStackTrace();
            }

            TopAreanHandle.TopAreanEnum nextState = topAreanModule.getState().getNext();
            try {
                updateState(topAreanModule, nextState);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 在该区初始化活动
     */
    private void initTopArean(TopAreanModule topAreanModule, DateTime now) {
        logger.info("日志4：%s区,巅峰赛重置", topAreanModule.getAreaId(), now, topAreanModule.getStateTimes().get(topAreanModule.getState()));
        //1.初始化巅峰赛的(1)时间表,(2)当前所处状态,(3)活动是否开启开关,(4)开始时间
        DateTime startTime = now.withTimeAtStartOfDay();//活动开始时间
        topAreanModule.resetState(startTime);
    }

    /**
     * 检查是否满足初始化要求
     */
    private boolean checkCondition(TopAreanModule topAreanModule, DateTime now) {
        try {
            logger.info("日志1：%s区,当前时间的初始时间:%s,当前状态的结束时间%s,当前状态%s",
                    topAreanModule.getAreaId(),
                    now,
                    topAreanModule.getStateTimes().get(topAreanModule.getState()),
                    topAreanModule.getState().name()
            );
        } catch (Exception e) {
            e.printStackTrace();
        }

        /**
         * 当前时间在开始时间之前特殊处理:一般不会发生,除非2种情况
         * 1.改服务器时间
         * 2.开始活动后第二天竞技场人数不足
         * 这种情况直接初始化活动表时间表,让活动从当前时刻开始
         */
        DateTime specialStartTime = topAreanModule.getStartTime();
        if (specialStartTime.isAfter(now)) {
            return true;
        }

        //1.竞技场排行榜人数是否满足要求,必须是>64人,不足64人就从战力榜里面拿
        int areaId = topAreanModule.getAreaId();
        AreaBean areaBean = AreaBean.get(areaId);

        RankArena rankArena = new RankArena(areaBean);
        Collection<RankEntry> range = rankArena.range(Constant.ONE, Constant.SIXTY_FOUR);//竞技场排行榜1-64名

        RankPlayerPower rankPlayerPower = new RankPlayerPower(areaBean);
        Collection<RankEntry> rangePower = rankPlayerPower.range(Constant.ONE, Constant.SIXTY_FOUR);//战力排行榜1-64名

        List<String> playerCodes = range.stream().map(_range -> _range.getKey()).collect(Collectors.toList());//竞技场排行64名玩家code
        List<String> playerCodesPowers = rangePower.stream().map(_range -> _range.getKey()).collect(Collectors.toList());//战力排行榜64名玩家code

        if (playerCodes.size() < Constant.SIXTY_FOUR) {
            //从战力排行榜拿壮丁
            for (String playerCodesPower : playerCodesPowers) {
                if (playerCodes.contains(playerCodesPower) || playerCodes.size() >= Constant.SIXTY_FOUR) {
                    continue;
                }
                playerCodes.add(playerCodesPower);
            }
        }
        if (playerCodes.size() < Constant.SIXTY_FOUR) {
            //如果是在赛季结束期间人数少于64人,这种情况直接初始化活动表时间表,让活动从当前时刻开始
            int number = topAreanModule.getState().getState().getNumber();
            if (number == 0) {
                logger.info("%s区,竞技场巅峰赛参赛人数不够重置活动,%s", areaBean.getAreaId(), range.size());
                return true;
            }
        }
        //2.是否已经结算完毕
        boolean running = topAreanModule.isRunning();
        if (running) {
            logger.info("日志2：%s区,竞技场巅峰赛是否结算完毕%s", topAreanModule.getAreaId(), !running);
            return false;
        }
        //3.是否满足时间要求 必须是在已结算完的开始时间的3天过5小时之后
        long startTime = topAreanModule.getStartTime().plusDays(Constant.THREE).plusHours(5).withTimeAtStartOfDay().getMillis();
        long nowTime = now.getMillis();
        logger.info("日志3：%s区,竞技场巅峰赛开始时间long值：%s，结束时间long值：%s", topAreanModule.getAreaId(), startTime, nowTime);
        if (nowTime <= startTime) {
            return false;
        }
        return true;
    }

    /**
     * 修改活动状态,处理新状态业务
     */
    private void updateState(TopAreanModule topAreanModule, TopAreanHandle.TopAreanEnum state) {
        switch (state) {
            case STEP_PREPARE:
                logger.info("巅峰赛日志2-修改STEP_PREPARE状态：%s区,状态为：%s,",topAreanModule.getAreaId(),state.name());
                break;
            case STEP_GROUP:
                groupTop64(topAreanModule);//初始化64强
                break;
            case STEP_QUIZ64:
                logger.info("巅峰赛日志3-修改STEP_QUIZ64状态：%s区,状态为：%s,",topAreanModule.getAreaId(),state.name());
                topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ64);//更新64强竞猜中状态
                topAreanModule.set();
                break;
            case STEP_QUIZ32:
                groupTop32(topAreanModule);//初始化32强
                break;
            case STEP_QUIZ16:
                groupTop16(topAreanModule);//初始化16强
                break;
            case STEP_OFFSEASONGROUP:
                groupTop8(topAreanModule);
                break;
            case STEP_APEREADY:
                groupTop8_2(topAreanModule);//初始化8强和冠军赛
                break;
            case STEP_QUIZ8:
                logger.info("巅峰赛日志4-修改STEP_QUIZ8状态：%s区,状态为：%s,",topAreanModule.getAreaId(),state.name());
                topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ8);//更新8强竞猜中状态
                topAreanModule.set();
                break;
            case STEP_QUIZ4:
                groupTop4(topAreanModule);//初始化4强
                break;
            case STEP_QUIZ2:
                groupTop2(topAreanModule);//初始化2强
                break;
            case STEP_OFFSEASON:
                groupTop(topAreanModule);//决赛
                break;
            default:
                logger.info("巅峰赛日志5-默认状态状态：%s区,状态为：%s,",topAreanModule.getAreaId(),state.name());
                break;
        }
    }

    //2强竞猜结束
    private void groupTop(TopAreanModule topAreanModule) {
        logger.info("%s区,竞技场巅峰赛2强竞猜结束", topAreanModule.getAreaId());
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_OFFSEASON);//更新结束展示状态
        //更新赛季运行状态和活动转换为结束展示状态
        topAreanModule.addGrouping();
        topAreanModule.set();
        List<String> playerCodes = new ArrayList<>();
        // 决赛战斗和2强竞猜奖励结算
        TopAreanStructure topAreanStructure = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.FINAL, 9);
        //更新冠军玩家状态
        String winnerPlayerCode = topAreanStructure.getWinner().getPlayerCode();
        TopAreanPlayerModule topAreanPlayerModule = TopAreanPlayerModule.get(winnerPlayerCode);
        topAreanPlayerModule.rankLevelUp(TopAreanHandle.TopAreanLevel.Winner);
        topAreanPlayerModule.set();
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_OFFSEASON);//更新结束展示状态
        topAreanModule.set();
        //做保护,状态前置后,给前8强发奖排名奖,给未出线的56名玩家发参与奖
        sendReward(topAreanModule);
    }


    //4强竞猜结束,进行2强初始化
    private void groupTop2(TopAreanModule topAreanModule) {
        logger.info("%s区,竞技场巅峰赛4强竞猜结束,进行2强初始化", topAreanModule.getAreaId());
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ2);//更新2强竞猜中状态
        topAreanModule.set();
        List<String> playerCodes = new ArrayList<>();
        // 冠军4强战斗和4强竞猜奖励结算
        TopAreanStructure topAreanFINAL1256 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F1256, 9);
        TopAreanStructure topAreanFINAL3478 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F3478, 9);
        playerCodes.add(topAreanFINAL1256.getWinner().getPlayerCode());
        playerCodes.add(topAreanFINAL3478.getWinner().getPlayerCode());
        // 冠军赛2强初始化
        topAreanModule.addGrouping2(playerCodes, 9);
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ2);//更新2强竞猜中状态
        topAreanModule.set();
    }

    //8强竞猜结束,进行4强初始化
    private void groupTop4(TopAreanModule topAreanModule) {
        logger.info("%s区,竞技场巅峰赛8强竞猜结束,进行4强初始化", topAreanModule.getAreaId());
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ4);//更新4强竞猜中状态
        topAreanModule.set();
        List<String> playerCodes = new ArrayList<>();
        // 冠军8强战斗和8强竞猜奖励结算
        TopAreanStructure topAreanFINAL12 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F12, 9);
        TopAreanStructure topAreanFINAL56 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F56, 9);
        TopAreanStructure topAreanFINAL34 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F34, 9);
        TopAreanStructure topAreanFINAL78 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F78, 9);
        playerCodes.add(topAreanFINAL12.getWinner().getPlayerCode());
        playerCodes.add(topAreanFINAL56.getWinner().getPlayerCode());
        playerCodes.add(topAreanFINAL34.getWinner().getPlayerCode());
        playerCodes.add(topAreanFINAL78.getWinner().getPlayerCode());
        // 冠军赛4强初始化
        topAreanModule.addGrouping4(playerCodes, 9);
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ4);//更新4强竞猜中状态
        topAreanModule.set();
    }

    //小组赛展示结束,进行8强初始化
    private void groupTop8_2(TopAreanModule topAreanModule) {
        logger.info("%s区,竞技场巅峰赛16强竞猜结束,进行8强初始化", topAreanModule.getAreaId());
        List<String> playerCodes = new ArrayList<>();
        // 冠军赛8强初始化
        for (int i = 1; i <= 8; i++) {
            TopAreanStructure topAreanStructure = topAreanModule.matchGroup(i).get(TopAreanHandle.TopAreanCode.FINAL);
            playerCodes.add(topAreanStructure.getWinner().getPlayerCode());
        }
        List<String> allPlyaerCodes = topAreanModule.getPlyaerCodes();
        allPlyaerCodes.removeAll(playerCodes);
        //没晋级的玩家全部更新为小组赛未出线状态
        for (String allPlyaerCode : allPlyaerCodes) {
            TopAreanPlayerModule topAreanPlayerModule = TopAreanPlayerModule.get(allPlyaerCode);
            topAreanPlayerModule.rankLevelUp(TopAreanHandle.TopAreanLevel.Group);
            topAreanPlayerModule.set();
        }
        allPlyaerCodes.addAll(playerCodes);
        topAreanModule.addGrouping8(playerCodes, 9);
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_APEREADY);//更新冠军赛准备中状态
        topAreanModule.set();
    }

    //16强竞猜结束,进行小组赛展示阶段
    private void groupTop8(TopAreanModule topAreanModule) {
        logger.info("%s区,竞技场巅峰赛16强竞猜结束,进行小组赛展示阶段", topAreanModule.getAreaId());
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_OFFSEASONGROUP);//更新小组赛结束展示状态
        topAreanModule.set();
        List<String> playerCodes = new ArrayList<>();
        for (int i = 1; i <= 8; i++) {
            // 小组16强战斗和16强竞猜奖励结算
            TopAreanStructure topAreanFINAL = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.FINAL, i);
            playerCodes.add(topAreanFINAL.getWinner().getPlayerCode());
        }
        //晋级的玩家更新为小组赛冠军
        for (String playerCode : playerCodes) {
            TopAreanPlayerModule topAreanPlayerModule = TopAreanPlayerModule.get(playerCode);
            topAreanPlayerModule.rankLevelUp(TopAreanHandle.TopAreanLevel.GroupWinner);
            topAreanPlayerModule.set();
        }
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_OFFSEASONGROUP);//更新小组赛结束展示状态
        topAreanModule.set();
    }

    //32强竞猜结束,进行16强初始化
    private void groupTop16(TopAreanModule topAreanModule) {
        logger.info("%s区,竞技场巅峰赛32强竞猜结束,进行16强初始化", topAreanModule.getAreaId());
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ16);//更新16强竞猜中状态
        topAreanModule.set();
        for (int i = 1; i <= 8; i++) {
            // 小组32强战斗和32强竞猜奖励结算
            List<String> playerCodes = new ArrayList<>();
            TopAreanStructure topArean1256 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F1256, i);
            TopAreanStructure topArean3478 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F3478, i);
            playerCodes.add(topArean1256.getWinner().getPlayerCode());
            playerCodes.add(topArean3478.getWinner().getPlayerCode());
            // 小组赛32强初始化
            topAreanModule.addGrouping16(playerCodes, i);
        }
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ16);//更新16强竞猜中状态
        topAreanModule.set();
    }


    //64强竞猜结束,进行32强初始化
    private void groupTop32(TopAreanModule topAreanModule) {
        logger.info("%s区,竞技场巅峰赛64强竞猜结束,进行32强初始化", topAreanModule.getAreaId());
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ32);//更新32强竞猜中状态
        topAreanModule.set();
        for (int i = 1; i <= 8; i++) {
            // 小组64强战和64强竞猜奖励结算
            List<String> playerCodes = new ArrayList<>();
            TopAreanStructure topArean12 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F12, i);
            TopAreanStructure topArean56 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F56, i);
            TopAreanStructure topArean34 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F34, i);
            TopAreanStructure topArean78 = topAreanModule.handleBattle(TopAreanHandle.TopAreanCode.F78, i);
            playerCodes.add(topArean12.getWinner().getPlayerCode());
            playerCodes.add(topArean56.getWinner().getPlayerCode());
            playerCodes.add(topArean34.getWinner().getPlayerCode());
            playerCodes.add(topArean78.getWinner().getPlayerCode());
            // 小组赛32强初始化
            topAreanModule.addGrouping32(playerCodes, i);
        }
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_QUIZ32);//更新32强竞猜中状态
        topAreanModule.set();
    }

    //休赛日结束,进行小组赛分组和64强初始化
    private void groupTop64(TopAreanModule topAreanModule) {
        int areaId = topAreanModule.getAreaId();
        AreaBean areaBean = AreaBean.get(areaId);
        RankArena rankArena = new RankArena(areaBean);
        //TODO 这里需要检查是不是获取的1-64名
        Collection<RankEntry> range = rankArena.range(Constant.ONE, Constant.SIXTY_FOUR);//竞技场排行1-64名
        RankPlayerPower rankPlayerPower = new RankPlayerPower(areaBean);
        Collection<RankEntry> rangePower = rankPlayerPower.range(Constant.ONE, Constant.SIXTY_FOUR);//战力排行榜1-64名


        logger.info("%s区,竞技场巅峰赛进行小组赛分组和64强初始化", areaBean.getAreaId());
        List<String> playerCodes = range.stream().map(_range -> _range.getKey()).collect(Collectors.toList());//竞技场排行64名玩家code
        List<String> playerCodesPowers = rangePower.stream().map(_range -> _range.getKey()).collect(Collectors.toList());//战力排行榜64名玩家code
        if (playerCodes.size() < Constant.SIXTY_FOUR) {
            //从战力排行榜拿壮丁
            for (String playerCodesPower : playerCodesPowers) {
                if (playerCodes.contains(playerCodesPower) || playerCodes.size() >= Constant.SIXTY_FOUR) {
                    continue;
                }
                playerCodes.add(playerCodesPower);
            }
        }
        if (playerCodes.size() < Constant.SIXTY_FOUR) {
            logger.error("%s区,竞技场巅峰赛参赛人数不够,%s", areaBean.getAreaId(), range.size());
            return;
        }

        topAreanModule.setPlyaerCodes(playerCodes);
        Collections.shuffle(playerCodes);//洗牌
        topAreanModule.clearGroupAndFinal();//清除旧赛程数据
        //64强开始分组1-8
        topAreanModule.addGrouping64(playerCodes.subList(0, 8), 1);
        topAreanModule.addGrouping64(playerCodes.subList(8, 16), 2);
        topAreanModule.addGrouping64(playerCodes.subList(16, 24), 3);
        topAreanModule.addGrouping64(playerCodes.subList(24, 32), 4);
        topAreanModule.addGrouping64(playerCodes.subList(32, 40), 5);
        topAreanModule.addGrouping64(playerCodes.subList(40, 48), 6);
        topAreanModule.addGrouping64(playerCodes.subList(48, 56), 7);
        topAreanModule.addGrouping64(playerCodes.subList(56, 64), 8);
        topAreanModule.setState(TopAreanHandle.TopAreanEnum.STEP_GROUP);//更新巅峰小组赛准备中状态
        topAreanModule.set();
    }

    /**
     * 前8名发排名奖励,其他56名发送参与奖励
     */
    private void sendReward(TopAreanModule topAreanModule) {
        //获取冠军
        String playerCode_top1 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.FINAL).getWinner().getPlayerCode();
        //获取亚军
        String playerCode_top2 = null;
        String playerCode_temp = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.FINAL).getPlayer1().getPlayerCode();
        if (playerCode_temp.equals(playerCode_top1)) {
            playerCode_top2 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.FINAL).getPlayer2().getPlayerCode();
        } else {
            playerCode_top2 = playerCode_temp;
        }
        //获取4强-2名
        List<String> playerCode_top4 = new ArrayList<>();
        String playerCode_top4_1 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F1256).getPlayer1().getPlayerCode();
        String playerCode_top4_2 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F3478).getPlayer1().getPlayerCode();
        String playerCode_top4_3 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F1256).getPlayer2().getPlayerCode();
        String playerCode_top4_4 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F3478).getPlayer2().getPlayerCode();
        playerCode_top4.add(playerCode_top4_1);
        playerCode_top4.add(playerCode_top4_2);
        playerCode_top4.add(playerCode_top4_3);
        playerCode_top4.add(playerCode_top4_4);
        playerCode_top4.remove(playerCode_top1);
        playerCode_top4.remove(playerCode_top2);
        //获取8强-4名
        List<String> playerCode_top8 = new ArrayList<>();
        String playerCode_top8_1 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F12).getPlayer1().getPlayerCode();
        String playerCode_top8_2 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F34).getPlayer1().getPlayerCode();
        String playerCode_top8_3 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F56).getPlayer1().getPlayerCode();
        String playerCode_top8_4 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F78).getPlayer1().getPlayerCode();
        String playerCode_top8_5 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F12).getPlayer2().getPlayerCode();
        String playerCode_top8_6 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F34).getPlayer2().getPlayerCode();
        String playerCode_top8_7 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F56).getPlayer2().getPlayerCode();
        String playerCode_top8_8 = topAreanModule.getFinals().get(TopAreanHandle.TopAreanCode.F78).getPlayer2().getPlayerCode();
        playerCode_top8.add(playerCode_top8_1);
        playerCode_top8.add(playerCode_top8_2);
        playerCode_top8.add(playerCode_top8_3);
        playerCode_top8.add(playerCode_top8_4);
        playerCode_top8.add(playerCode_top8_5);
        playerCode_top8.add(playerCode_top8_6);
        playerCode_top8.add(playerCode_top8_7);
        playerCode_top8.add(playerCode_top8_8);
        playerCode_top8.removeAll(playerCode_top4);
        playerCode_top8.remove(playerCode_top1);
        playerCode_top8.remove(playerCode_top2);
        //参与奖玩家
        List<String> plyaerCode_temp_2 = topAreanModule.getPlyaerCodes();
        List<String> playerCode_top64 = plyaerCode_temp_2.stream().collect(Collectors.toList());
        playerCode_top64.remove(playerCode_top1);
        playerCode_top64.remove(playerCode_top2);
        playerCode_top64.removeAll(playerCode_top4);
        playerCode_top64.removeAll(playerCode_top8);
        logger.error("%s区-竞技场巅峰赛开始发排名奖和参与奖,冠军:%s,亚军:%s,4强:%s,8强:%s,参与:%s",
                topAreanModule.getAreaId(),
                playerCode_top1,
                playerCode_top2,
                JSON.toJSONString(playerCode_top4),
                JSON.toJSONString(playerCode_top8),
                JSON.toJSONString(playerCode_top64)
        );
        //开始发奖
        String title_top1 = GameString.竞技场巅峰赛名次冠军_titl().getText();
        String content_top1 = GameString.竞技场巅峰赛名次冠军_msg().getText();
        arenarankreward data_top1 = DataCenter.getData(113, arenarankreward.class);
        Currencies rewards_top1 = new Currencies(Currency.create(data_top1.getRewardtype(), data_top1.getRewardid(), data_top1.getRewardnum()));
        new MailHandle().sendMail(playerCode_top1, MailTypeEnum.Mail, title_top1, content_top1, CCReason.巅峰赛, rewards_top1);

        String title_top2 = GameString.竞技场巅峰赛名次亚军_titl().getText();
        String content_top2 = GameString.竞技场巅峰赛名次亚军_msg().getText();
        arenarankreward data_top2 = DataCenter.getData(114, arenarankreward.class);
        Currencies rewards_top2 = new Currencies(Currency.create(data_top2.getRewardtype(), data_top2.getRewardid(), data_top2.getRewardnum()));
        new MailHandle().sendMail(playerCode_top2, MailTypeEnum.Mail, title_top2, content_top2, CCReason.巅峰赛, rewards_top2);

        String title_top4 = GameString.竞技场巅峰赛名次四强_titl().getText();
        String content_top4 = GameString.竞技场巅峰赛名次四强_msg().getText();
        arenarankreward data_top4 = DataCenter.getData(115, arenarankreward.class);
        for (String playerCode : playerCode_top4) {
            Currencies rewards_top4 = new Currencies(Currency.create(data_top4.getRewardtype(), data_top4.getRewardid(), data_top4.getRewardnum()));
            new MailHandle().sendMail(playerCode, MailTypeEnum.Mail, title_top4, content_top4, CCReason.巅峰赛, rewards_top4);
        }

        String title_top8 = GameString.竞技场巅峰赛名次八强_titl().getText();
        String content_top8 = GameString.竞技场巅峰赛名次八强_msg().getText();
        arenarankreward data_top8 = DataCenter.getData(116, arenarankreward.class);
        for (String playerCode : playerCode_top8) {
            Currencies rewards_top8 = new Currencies(Currency.create(data_top8.getRewardtype(), data_top8.getRewardid(), data_top8.getRewardnum()));
            new MailHandle().sendMail(playerCode, MailTypeEnum.Mail, title_top8, content_top8, CCReason.巅峰赛, rewards_top8);
        }

        String title_top64 = GameString.竞技场巅峰赛参与奖_titl().getText();
        String content_top64 = GameString.竞技场巅峰赛参与奖_msg().getText();
        arenarankreward data_top64 = DataCenter.getData(117, arenarankreward.class);
        for (String playerCode : playerCode_top64) {
            Currencies rewards_top64 = new Currencies(Currency.create(data_top64.getRewardtype(), data_top64.getRewardid(), data_top64.getRewardnum()));
            new MailHandle().sendMail(playerCode, MailTypeEnum.Mail, title_top64, content_top64, CCReason.巅峰赛, rewards_top64);
        }
    }
}
